*Title: "Enforcing Economic Sanctions by Tarnishing Corporate Reputations" 
*Journal: Business and Politics
*Authors: Keith A. Preble (Miami University) and Bryan R. Early (SUNY Albany)
*DO File for Replication

*Set graphing environment
*ssc install brewscheme
set scheme plotplainblind

*Load data
use "BAP_MasterData.dta", clear

*Figure 1
graph bar (count), over(Foreign) over(Profile_poly_pcf1, label(angle(45) ticks) relabel(1 "Lowest Profile" 2 "Brand" 3 "Publicly Traded" 4 "Brand & Fortune500" 5 "Publicly Traded & Brand" 6 "Publicly Traded & Fortune500" 7 "Highest Profile")) asyvars bargap(30) ytitle("Number of Firms") title("Domestic and Foreign Firms Across Level of Profile") blabel(bar) ylabel(0(20)100) 

**REGRESSION ANALYSIS

*Gamma log-link (DV: Penalty in 2021 USD)
*Gamma log-link is a useful method when the date is right-skewed and there's no zeroes in the DV (there aren't for our data); this helps us avoid issues with back transforming the logged DV and helps with interpretability of the interaction.
eststo M1a: glm RealPSAmt2021 c.Profile_poly_pcf1 if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

eststo M1b: glm RealPSAmt2021 c.Profile_poly_pcf1 i.Foreign if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

eststo M1c: glm RealPSAmt2021 c.Profile_poly_pcf1 i.Foreign i.FinServ i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

eststo M1d: glm RealPSAmt2021 c.Profile_poly_pcf1##i.Foreign i.FinServ i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

*Profile t-test
ttest Profile_poly_pcf1 if e(sample), by(Foreign)

*Combined Figures for Appendix:
margins Foreign, at(Profile_=(0(.05)1.055)) level(95) saving(myfile, replace)
marginsplot

*Regression Table, Table 1
*On screen
esttab M1a M1b M1c M1d, label se r2 pr2 replace star(+ 0.10 * 0.05) 

*Table 1 for printing
esttab M1a M1b M1c M1d using table1_4mod.rtf, compress label star(+ 0.10 * 0.05) se 


**************CREATING Table 2a-2b and Figure 2***********

*First, run regression with interaction:
eststo M1d: glm RealPSAmt2021 c.Profile_poly_pcf1##i.Foreign i.FinServ i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

*Run to get Data for Table 2a-2b (then copy data to Excel and paste table to Word)
margins Foreign, at(Profile_=(0 .3448256 .3585003 .6965009 .7033259 .7101756 1.055001)) level(95) post

*Figure 2
*Re-run regression if needed:
eststo M1d: glm RealPSAmt2021 c.Profile_poly_pcf1##i.Foreign i.FinServ i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

*Create marginal effects and save data to a new file
margins Foreign, at(Profile_=(0(.05)1.055)) level(95) saving(myfile, replace)

*Load file with marginal effects for graph
use myfile, clear

*Generate Figure 2, which places domestic and foreign side-by-side:
*Foreign Firms Figure
graph twoway (rarea _ci_ub _ci_lb _at1) /// 
	|| (line _margin _at1) if _m1==1, title("Foreign Firms") xtitle("Profile") ytitle("Penalty (2021 USD)") legend(position(6) cols(3)) saving(graph1, replace)
	
*Domestic Firms Figure
graph twoway (rarea _ci_ub _ci_lb _at1) /// 
	|| (line _margin _at1) if _m1==0, title("Domestic Firms") xtitle("Profile") ytitle("Penalty (2021 USD)") legend(position(6) cols(3)) saving(graph2, replace)
	
*Combine the two figures:
graph combine graph1.gph graph2.gph

********ONLINE APPENDIX -- To check the statistical significance of overlapping confidence intervals***************

*Reload the original data:
use "BAP_MasterData.dta", clear

*This analysis is used to check whether there's any statistical difference between the marginal effects for foreign and domestic firms (which was a concern of reviewers; this analysis is done in the online supplementary material but anyone can re-run it for themselves):
*First run the regression:
eststo M1d: glm RealPSAmt2021 c.Profile_poly_pcf1##i.Foreign i.FinServ i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

*Calculate marginal effects and save data to a new file
margins Foreign, at(Profile_=(0(.05)1.055)) level(95) saving(myfile, replace)

*Load the new file created from margins command:
use myfile 

*Purge variables and reshape the data:
drop _at1 _at2 _at3 _at4 _at5 _at6 _ci_ub _ci_lb _pvalue _statistic _se_margin _atopt _predict _term _deriv
reshape wide _margin, i(_at) j(_m1) 

*Run the paired t-test:
ttest _margin0 = _margin1

************************* OLS REGRESSION RESULTS USING LOG-TRANSFORMED DEPENDENT VARIABLE *******************
*OLS Regression (DV: ln Penalty in 2021 USD)
*We also perform the OLS model (log-linear)
*We opted for a glm model with gamma log link because percent changes in fines are not as intuitive as the back transformation that is possible with the glm (and not as easy to do with OLS when the DV is log-transformed):

*Reload the original data:
use "BAP_MasterData.dta", clear

eststo M3a: reg ln_RealPSAmt2021 c.Profile_poly_pcf1 if Entity==1 & FOV !=1, vce(robust) level(95)

eststo M3b: reg ln_RealPSAmt2021 c.Profile_poly_pcf1 i.Foreign if Entity==1 & FOV !=1, vce(robust) level(95) 

eststo M3c: reg ln_RealPSAmt2021 c.Profile_poly_pcf1 i.Foreign i.FinServ i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) 

eststo M3d: reg ln_RealPSAmt2021 c.Profile_poly_pcf1##i.Foreign i.FinServ i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95)

*Regression Table (screen)
esttab M3a M3b M3c M3d, label se r2 replace star(* 0.05) scalar(rmse)

*Regression Table (for printing)
esttab M3a M3b M3c M3d using table_app_final.rtf, compress label star(* 0.05) se r2 scalar(rmse)

***ADDITIONAL REGRESSION ANALYSIS

eststo A1: glm RealPSAmt2021 i.Foreign i.FinServ i.Brand  i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

eststo A2: glm RealPSAmt2021 i.Foreign i.FinServ i.Fortune500 i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

eststo A3: glm RealPSAmt2021 i.Foreign i.FinServ i.PubTrade i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

eststo A4: glm RealPSAmt2021 i.Foreign i.FinServ i.Brand i.Fortune500 i.PubTrade i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

esttab A1 A2 A3 A4 using table_app_alt.rtf, label se replace star(* 0.05) 

**OLS
eststo A1: glm RealPSAmt2021 i.Foreign i.Brand i.FinServ  i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

eststo A2: glm RealPSAmt2021 i.Foreign##i.Brand i.FinServ  i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

margins Foreign#Brand
mplotoffset

eststo A3: glm RealPSAmt2021 i.Foreign i.Fortune500 i.FinServ  i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

eststo A4: glm RealPSAmt2021 i.Foreign##i.Fortune500 i.FinServ  i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

margins Foreign#Fortune500
mplotoffset

eststo A5: glm RealPSAmt2021 i.Foreign i.PubTrade i.FinServ  i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

eststo A6: glm RealPSAmt2021 i.Foreign##i.PubTrade i.FinServ  i.VoluntDisc i.Egregious_alt i.Administration if Entity==1 & FOV !=1, vce(robust) level(95) link(log) fam(gamma)

margins Foreign#PubTrade
mplotoffset

*On screen display
esttab A1 A2 A3 A4 A5 A6, label se replace star(* 0.05) 

*Regression Table
esttab A1 A2 A3 A4 A5 A6 using table_app_alt.rtf, label se replace star(* 0.05) 

************EXPLORATORY FACTOR ANALYSIS***************
*Exploratory Factor Analysis using polychoric correlations
*The Factor Variable we create IS ALREADY IN THE DATA SET so if you run this, it won't run because the variable has already been created.
*Includes tests to check fit and whether FA is applicable

*Load data:
use "BAP_MasterData.dta", clear

*Check for errors in the data as well as skewness and kurtosis
tabstat PubTrade Brand Fortune, statistics(count mean sd min max skewness kurtosis)

*Test of normality of the components
mvtest normality PubTrade Brand Fortune, stats(all)

*Perform factortest before running FA
*You want KMO test to be greater than 0.6 given small sample size
*p-value should be less than 0.05
factortest PubTrade Brand Fortune 

*Pearson correlation coefficients - compare to next command
corrci PubTrade Brand Fortune

*Create matrix
polychoric PubTrade Brand Fortune
display r(sum_w)
global N = r(sum_w)
matrix r = r(R)

*Generate factors
factormat r, pcf n($N) factors(3)

*Goodness of fit
estat kmo

*Cronbach's Alpha w/ confidence interval
alpha PubTrade Brand Fortune 
cialpha

*Rotate factors
rotate, promax oblique

*Create new variable
predict Profile_poly_pcf1




